package com.dingding.service.user.core.dao.impl;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.UserTaxiOrdert;
import com.dingding.order.dto.confirm.PushTaxiConfirmArrival;
import com.dingding.service.user.core.dao.ITaxiConfirmArriveDao;
import com.dingding.service.user.core.sql.TaxiConfirmArriveSQL;

/**
 * 
 * @ClassName: TaxiConfirmArriveDaoImpl 
 * @Description: 出租车确认到达DAO实现类 
 * @author YHQ
 * @date 2016年7月1日 上午10:59:27
 * 
 */
@Component("taxiConfirmArriveDao")
public class TaxiConfirmArriveDaoImpl extends BaseDaoImpl<UserTaxiOrdert> implements ITaxiConfirmArriveDao {

	/**
	 * 
	 * @Title: getConfirmArrival 
	 * @param passengerId 乘客Id
	 * @param driverId 司机Id
	 * @author YHQ
	 * @version V2.3.0
	 */
	@Override
	@Transactional(readOnly = true)
	public PushTaxiConfirmArrival getConfirmArrival(String passengerId, String driverId) {

		// 根据司机Id,获取司机信息
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(TaxiConfirmArriveSQL.PASSENGER_PAY_PUSH, driverId, passengerId);
		} catch (Exception e) {
			log.info("乘客支付获取推送内容时出现异常  类：" + this.getClass() + " getPassengerPayPushInfo()", e);
		}

		// 创建乘客支付成功，给司机推送Bean
		PushTaxiConfirmArrival taxiConfirmArrival = new PushTaxiConfirmArrival();
		
		// 判断司机信息是否为空
		if (obj != null && obj.length > 0) {

			// 将司机信息赋值给pushPassengerPay
			this.getPushConfirmArrival(obj, taxiConfirmArrival);
		}

		return taxiConfirmArrival;

	}

	/**
	 * 
	 * @Title: getConfirmArrival 
	 * @param passengerId 乘客Id
	 * @param driverId 司机Id
	 * @author YHQ
	 * @version V2.3.0
	 */
	@Override
	@Transactional(readOnly = true)
	public PushTaxiConfirmArrival getTaxiConfirmArrival(String passengerId, String driverId) {

		// 根据司机Id,获取司机信息
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(TaxiConfirmArriveSQL.PASSENGER_PAY_TAXI_PUSH, driverId, passengerId);
		} catch (Exception e) {
			log.info("乘客支付获取推送内容时出现异常  类：" + this.getClass() + " getPassengerPayPushInfo()", e);
		}

		// 创建乘客支付成功，给司机推送Bean
		PushTaxiConfirmArrival taxiConfirmArrival = new PushTaxiConfirmArrival();
		
		// 判断司机信息是否为空
		if (obj != null && obj.length > 0) {

			// 将司机信息赋值给pushPassengerPay
			this.getPushConfirmArrival(obj, taxiConfirmArrival);
		}

		return taxiConfirmArrival;

	}
	
	/**
	 * 
	 * @Title: getPushConfirmArrival 
	 * @Description: 出租车确认到达 - 推送数据转换
	 * @param obj 推送内容
	 * @param pushConfirmArrival 存储推送内容Bean
	 * @author YHQ 
	 * @version V2.3.0
	 * @return void    返回类型
	 */
	public void getPushConfirmArrival(Object[] obj, PushTaxiConfirmArrival taxiConfirmArrival) {

		// 乘客Id(推送Id)
		if (obj[0] != null) {
			taxiConfirmArrival.setDriverId(obj[0].toString());
		}
		// 设备类型
		if (obj[1] != null) {
			// 设备类型 1:iOS 2:Android
			String deviceType = obj[1].toString();

			if (deviceType.equals("1")) { // 设备类型为：iOS
				taxiConfirmArrival.setLoginEquipment("iOS");
			} else if (deviceType.equals("2")) { // 设备类型为：Android
				taxiConfirmArrival.setLoginEquipment("Android");
			}

		}
		// 乘客电话
		if (obj[2] != null) {
			taxiConfirmArrival.setTellPhone(obj[2].toString());
		}
		// 司机姓名
		if (obj[3] != null) {
			taxiConfirmArrival.setPassengerName(obj[3].toString());
		}
		// 乘客名称
		if (obj[4] != null) {
			taxiConfirmArrival.setDriverName(obj[4].toString());
		}
		// 车牌号
		if (obj[5] != null) {
			taxiConfirmArrival.setLisencePlate(obj[5].toString());
		}
	}
	
}
